
export const getListData=(data)=>{
    return {
        type:"GETLISTS",
        data
    }
}

export function addToCart(params){
	return dispatch=>{
		dispatch({
            type:"ADDTOCART",
            data:params
        })
	}
}

export function seeDetail(params){
	return dispatch=>{
		dispatch({
            type:"SEEDETAIL",
            data:params
        })
	}
}

export function fetchList(params={page:1,limit:8}){
    return dispatch=>{
        var start =20*(params.page-1);
        var url=`http://localhost:3000/product/list`;
        return fetch(url, {
            method: 'POST',
            headers: {
              'Content-Type': 'application/json'
            },
            body: JSON.stringify(params)
          })
        .then(res=>{
            return res.json()
        })
        .then((data)=>{
            dispatch(getListData(data));
        })
    }
}


export function totalPay(){
    return {
        type:'CALTOTAL'
    }
}



//添加的分类

//获取商品分类
export const getProductionClassify = (data) => {
    return {type: 'GETPRODUCTIONCLASSIFY', data}
}
export function fetchProductionClassify() {
    return dispatch => {
        var url = 'http://localhost:3000/cate/list';

        fetch(url, {method: 'get'}).then(res => {
            return res.json()
        }).then(data => {
            dispatch(getProductionClassify(data))
        })
    }
}

//商品详情
export const getProductionDetail = (data) => {
    return {type: 'GETPRODUCTIONCDETAIL', data}
}
export function fetchProductionDetail(params) {
    return dispatch => {
        var url = 'http://localhost:3000/product/data/'+params;

        fetch(url, {method: 'get'}).then(res => {
            return res.json()
        }).then(data => {
            dispatch(getProductionDetail(data))
        })
    }
}

//获取分类名称
export const getProductionType = (data) => {
    return {type: 'GETPRODUCTIONTYPE', data}
}
export function fetchProductionType(params) {
    return dispatch => {
        var url = 'http://localhost:3000/cate/data/'+params;

        fetch(url, {method: 'get'}).then(res => {
            return res.json()
        }).then(data => {
            dispatch(getProductionType(data))
        })
    }
}
